<template>
  <div class="classroomMamage">
    <el-card>
      <div class="search_wrap">
        <el-button type="primary">常规录制</el-button>
      </div>
      <div class="table_list">
        <el-table
          ref="nicheTable"
          :data="tableListData"
          min-height="500"
          border
          v-loading="loading"
          @selection-change="handleSelectionNiche"
          style="width: 100%;margin-top:20px"
        >
          <el-table-column type="selection" align="center" width="40" />
          <el-table-column
            v-for="(item,index) in tableCaption"
            :key="index"
            :label="item.label"
            align="center"
            :width="item.width"
          >
            <template slot-scope="scope">
              <span>{{ scope.row[item.value] }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
                <el-link type="primary" @click="playVideo(scope.row.playpath)">播放</el-link>
                <el-link type="danger" @click="handleDelete(scope.row.serial,scope.row.recordid)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>
        <link-pagination
          :total="total"
          :currentPage="currentPage"
          :limit="limit"
          v-if="total != 0"
          @pagination="getPaginationParams"
        ></link-pagination>
      </div>
    </el-card>
  </div>
</template>
<script>
import statisticsTag from "@/components/statisticsTag";
import { paginationMixin } from "@/mixin";
import http from "@/api/room";
import { formatDate, formatArray } from "@/utils";
export default {
  name: "recordsManage",
  mixins: [paginationMixin],
  components: {
    statisticsTag
  },
  data() {
    return {
      params:{
        id:"",
        serial:""
      },
      options: [
        {
          label: "全部",
          value: "classroomNumber"
        },
        {
          label: "当前教室",
          value: "classroomNumber"
        },
        {
          label: "未来教室",
          value: "classroomNumber"
        },
        {
          label: "历史教室",
          value: "classroomNumber"
        }
      ],
      http: http,
      selectedNum: 0,
      showBtn: false,
      showDelModal: false,
      searchCondition: null,
      queryDate: null,
      step: null,
      steps: null,
      type: null,
      types: null,
      loading: false,
      total: 1,
      tableCaption: [
        {
          label: "名称",
          value: "recordtitle",
          width: 150
        },
        {
          label: "创建时间",
          value: "starttime",
          width: 150
        },
        {
          label: "时长",
          value: "duration",
          width: 100
        },
        {
          label: "录制件大小",
          value: "size",
          width: 100
        },
        {
          label: "播放地址",
          value: "playpath",
          width: 500
        },
      ],
      tableListData: [],
      contractChangeStatusList: [],
      // statisticsTagData: [],
      status: null,
      contractStatusList: [],
      auditStatusList: [],
      examineModal: false,
      infoTittle: null,
      infoDetail: [],
      examineForm: {},
      examineRules: {},
      infoRemark: "",
      detailInfo: null,
      delNiche: null
    };
  },
  methods: {
    //删除教室
    confirmDelete() {
      let id = this.delNiche;
      http.deleteContent({ id }).then(res => {
        this.$message.success(res.msg || "删除成功");
        this.showDelModal = false;
        this.getListData();
      });
    },
    //路由跳转
    goToURL(name, params) {
      this.$router.push({ name, params });
    },
    searchStatus(status) {
      this.status = status;
      this.getListData();
    },
    goToURL(name, query) {
      this.$router.push({ name, query });
    },
    //播放录制件
    playVideo(params){
        window.open(params)
    },
     //删除
    handleDelete(serial,id) {
      var arr = []
      arr.push(id)
      var params = {
        serial:serial,
        fileidarr:arr
      }
      this.$confirm("确认删除吗?", "提示", {
        confirmButtonClass: "el-button--danger"
      }).then(() => {
          this.http.deleteContent(params).then(res => {
            this.$message.success(res.msg || "删除成功！");
            this.getListData();
          });
        })
        .catch(res => {
          console.log(res);
        });
    },
    queryListData(){
      this.getListData();
    },
    getListData(
      page = this.currentPage,
      list_rows = this.limit,
      search = this.searchCondition,
      status = this.status
    ) {
      this.loading = true;
      let params = { page, list_rows, search, status,serial:this.params.serial};
      if (this.queryDate) {
        params["create_time_start"] = formatDate.toStr(
          new Date(this.queryDate[0]),
          "YYYY-MM-DD"
        );
        params["create_time_end"] = formatDate.toStr(
          new Date(this.queryDate[1]),
          "YYYY-MM-DD"
        );
      }
      let basicConfig = JSON.parse(sessionStorage.getItem("basicConfig"));
      this.nicheStatus = formatArray(basicConfig.opport_status);
      console.log(basicConfig);
      http.getRoomRecordList(params).then(res => {
        this.loading = false;
        this.total = res.data.total;
        let tableListData = res.data;
        if (tableListData.length) {
          tableListData.map(item => {
            for (let niche of this.nicheStatus) {
              if (item.opport_status === niche.label.status) {
                item.opport_status = niche.label.label;
              }
            }
            for (let status of this.auditStatusList) {
              if (item.status - status.status === 0) {
                console.log(status);
                item.status = status.label;
              }
            }
          });
        }
        this.tableListData = tableListData;
        for (let row of this.tableListData) {
          for (let status of this.contractChangeStatusList) {
            if (row.varname === status.value) {
              row.varname = status.label;
            }
          }
        }
      });
    },
    //删除多个操作
    handleSelectionNiche(val) {
      console.log(val);
      this.selectionCustomer = val;
      this.selectedNum = this.selectionCustomer.length;
      if (this.selectedNum === 0) {
        this.showBtn = false;
      } else {
        this.showBtn = true;
      }
      if (this.selectionCustomer.length !== 0) {
        this.delNiche = [];
        for (let item of this.selectionCustomer) {
          this.delNiche.push(item.id);
        }
      }
    },
    init() {
      this.getListData();
      let basicConfig = JSON.parse(sessionStorage.getItem("basicConfig"));
      let contractChangeStatusList = [];
      let keysData = Object.keys(basicConfig.audit_varname);
      if (keysData.length) {
        keysData.map(item => {
          contractChangeStatusList.push({
            value: item,
            label: basicConfig.audit_varname[item]
          });
        });
        this.contractChangeStatusList = contractChangeStatusList;
      }
      let contractStatusList = [];
      let keysData1 = Object.keys(basicConfig.contract_status);
      if (keysData1.length) {
        keysData1.map(item => {
          contractStatusList.push({
            value: item,
            label: basicConfig.contract_status[item].a
          });
        });
        this.contractStatusList = contractStatusList;
      }
      this.auditStatusList = basicConfig.audit_status;

      this.levelList = formatArray(basicConfig.user_level);
      console.log(this.levelList);
    }
  },
  created() {
    this.params = this.$route.query;
    this.init();
  }
};
</script>
<style lang="scss" scoped>
.classroomMamage {
  padding: 10px;
  .opt_wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 34px;
    &_left {
      display: flex;
      p {
        margin-right: 18px;
        color: #565656;
        font-size: 16px;
        cursor: pointer;
        &:hover {
          color: #1796eb;
        }
        &:nth-of-type(1) {
          cursor: default;
          color: #646464;
          &:hover {
            color: #646464;
          }
        }
      }
    }
    &_right {
      display: flex;
      align-items: center;
      p {
        margin-left: 18px;
        color: #565656;
        font-size: 16px;
        cursor: pointer;
        &:hover {
          color: #1796eb;
        }
      }
      .add {
        width: 72px;
        height: 30px;
        background: linear-gradient(top left, #17b5eb, #1796eb);
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
        cursor: pointer;
        border-radius: 5px;
        &:hover {
          color: white;
        }
      }
    }
  }
  .search_wrap {
    margin-top: 34px;
    margin-bottom: 34px;
    div {
      margin-right: 17px;
    }
  }
  .see_detail {
    cursor: pointer;
    color: #1796eb;
  }
  .btn {
    margin-top: 30px;
    width: 100%;
    display: flex;
    justify-content: center;
    /deep/ .el-button {
      width: 214px;
    }
  }
  .del_modal {
    .content {
      display: flex;
      flex-direction: column;
      align-items: center;
      p {
        &:nth-of-type(1) {
          width: 92px;
          height: 92px;
          border-radius: 50%;
          background: linear-gradient(to bottom, #f25851, #f27350);
          display: flex;
          justify-content: center;
          align-items: center;
          margin-bottom: 18px;
          i {
            font-size: 40px;
            color: white;
          }
        }
        &:nth-of-type(2) {
          font-size: 20px;
          color: #333;
        }
        &:nth-of-type(3) {
          font-size: 14px;
          color: #999;
          margin-top: 7px;
        }
      }
    }
  }
  .operation {
    cursor: pointer;
    color: rgb(47, 156, 235);
  }
}
.el-table .success-row {
  background: #f0f9eb;
}
</style>